package com.example.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    private EditText editHello;
    private Button  bntSend;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editHello=(EditText) findViewById(R.id.editHello);
        bntSend=(Button) findViewById(R.id.btnSend);

        bntSend.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                //Intent intent=new Intent(MainActivity.this.SecondActivity.class);
                // startActivity(intent);
                Bundle bundle=new Bundle();
                bundle.putInt("num",1);
                bundle.putString("msg",editHello.getText().toString());

                //创建Intent对象，向Intent对象添加数据
                Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                intent.putExtras(bundle);

               // startActivity(intent);
                startActivityForResult(intent,1);
            }
       });
}

  protected void onActivityResult(int requestCode,int resultCode,Intent data) {
      super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == 1) {
          Bundle retBundle = data.getExtras();
          String retMsg = retBundle.getString("msg");

          editHello.setText("");
          editHello.setHint("收到回复:" + retMsg);
      }
  }
}
